/*    */ package com.om.common;
/*    */ 
/*    */ import java.awt.Color;
/*    */ import java.awt.Font;
/*    */ import java.awt.Graphics;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.util.Random;
/*    */ import javax.imageio.ImageIO;
/*    */ import javax.servlet.ServletOutputStream;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ 
/*    */ public class VaildateCode
/*    */ {
/*    */   public static void GenerateImage(HttpServletResponse response, HttpSession session)
/*    */   {
/* 18 */     ServletOutputStream so = null;
/*    */     try
/*    */     {
/* 21 */       response.setHeader("Pragma", "No-cache");
/* 22 */       response.setHeader("Cache-Control", "no-cache");
/* 23 */       response.setDateHeader("Expires", 0L);
/*    */ 
/* 26 */       int width = 60; int height = 20;
/* 27 */       BufferedImage image = new BufferedImage(width, height, 1);
/*    */ 
/* 30 */       Graphics g = image.getGraphics();
/*    */ 
/* 33 */       Random random = new Random();
/*    */ 
/* 36 */       g.setColor(getRandColor(200, 250));
/* 37 */       g.fillRect(0, 0, width, height);
/*    */ 
/* 40 */       g.setFont(new Font("Times New Roman", 0, 18));
/*    */ 
/* 48 */       g.setColor(getRandColor(160, 200));
/* 49 */       for (int i = 0; i < 155; ++i)
/*    */       {
/* 51 */         int x = random.nextInt(width);
/* 52 */         int y = random.nextInt(height);
/* 53 */         int xl = random.nextInt(12);
/* 54 */         int yl = random.nextInt(12);
/* 55 */         g.drawLine(x, y, x + xl, y + yl);
/*    */       }
/*    */ 
/* 59 */       String sRand = "";
/* 60 */       for (int i = 0; i < 4; ++i) {
/* 61 */         String rand = String.valueOf(random.nextInt(10));
/* 62 */         sRand = sRand + rand;
/*    */ 
/* 64 */         g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
/* 65 */         g.drawString(rand, 13 * i + 6, 16);
/*    */       }
/*    */ 
/* 69 */       session.setAttribute("vCode", sRand);
/*    */ 
/* 73 */       g.dispose();
/*    */ 
/* 77 */       so = response.getOutputStream();
/* 78 */       ImageIO.write(image, "JPEG", so);
/*    */     }
/*    */     catch (Exception localException)
/*    */     {
/*    */     }
/*    */   }
/*    */ 
/*    */   public static Color getRandColor(int fc, int bc)
/*    */   {
/* 88 */     Random random = new Random();
/* 89 */     if (fc > 255) fc = 255;
/* 90 */     if (bc > 255) bc = 255;
/* 91 */     int r = fc + random.nextInt(bc - fc);
/* 92 */     int g = fc + random.nextInt(bc - fc);
/* 93 */     int b = fc + random.nextInt(bc - fc);
/* 94 */     return new Color(r, g, b);
/*    */   }
/*    */ }

/* Location:           D:\temp\omtask\WEB-INF\classes\
 * Qualified Name:     com.om.common.VaildateCode
 * JD-Core Version:    0.5.3
 */